package Clases;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author eneko
 */
public class ProcessFile {

    String msg,filename;
    
    public ProcessFile(String filename)
    {
        this.filename=filename;
    }

    /**
    * Escribe en un fichero un String
    *
    * @param msg    String a escribir en el fichero
    */

    public synchronized void write(String msg)
    {
        FileWriter fw=null;
        try {
            fw = new FileWriter(filename, true);
            fw.write(msg);
            fw.flush();
            //fw.close();
        } catch (IOException ex) {
            Logger.getLogger(ProcessFile.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void read()
    {
        FileReader fr=null;
        BufferedReader bfr=null;

        

    }

    /**
    * Cuenta el número de líneas de un fichero.
    */


    public int countLines()
    {
        int lines=0;
        try
        {
            FileReader fr=new FileReader(filename);
            BufferedReader bf=new BufferedReader(fr);

            while(bf.readLine()!=null)
                lines++;

        }
        catch(FileNotFoundException ex){
            ex.printStackTrace();
        }
        catch(IOException ex){
            ex.printStackTrace();
        }

        return lines;
    }
}
